<template>
  <div :class="{backBig: isBig, back: !isBig}">
    <a
      class="back-inf"
      @click="back">
      <span>{{name}}</span>
    </a>
    <i class="iconfont icon-r-arrow"></i>
    <span :class="[moreBack ? 'pointer' : 'pointer hover']" @click="firstTitle">{{title}}</span>
    <div class="inline pointer">
      <slot name="left"></slot>
    </div>
    <div class="right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'zz-back',
    components: {},
    props: {
      backPath: {
        type: String
      },
      name: {
        type: String,
        default: '默认标题'
      },
      title: {
        type: String,
        default: '详情'
      },
      isBig: {
        type: Boolean,
        default: true
      },
      query: {
        type: Object,
        default: function () {
          return {}
        }
      },
      moreBack: {
        type: false,
        default: false
      }
    },
    methods: {
      back () {
        if (this.backPath) {
          if (Object.keys(this.query).length === 0) {
            this.$router.push({name: this.backPath})
          } else {
            this.$router.push({name: this.backPath, query: this.query})
          }
        } else {
          this.$router.go(-1)
        }
      },
      firstTitle () {
        if (this.moreBack) {
          this.$emit('firstTitleClick')
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .backBig{
    padding: 20px 20px 0 20px;
    .back-inf{
      &:hover{
        color: $color;
      }
    }
    .hover{
      color: $color;
    }
  }
  .back{
    height: 30px;
    line-height: 30px;
    padding:10px 0;
    font-size: $font-size-base;
    border-bottom: 1px $color-line solid;
    background: #fff;
    .back-inf{
      &:hover{
        color: $color;
      }
    }
    .hover{
      color: $color;
    }
  }
  .zz-back-approve {
    padding: 20px;
  }
</style>
